package com.neuedu.yyzx.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.dto.CustomerNurseItemDTO;
import com.neuedu.yyzx.dto.CustomerNurseSetDTO;
import com.neuedu.yyzx.po.Customer;
import com.neuedu.yyzx.po.Customernurseitem;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author HordEmpty
 * @description 针对表【customernurseitem】的数据库操作Mapper
 * @createDate 2025-04-18 16:46:22
 * @Entity com.neuedu.yyzx.domain.Customernurseitem
 */
public interface CustomernurseitemMapper extends BaseMapper<Customernurseitem> {
    @Select({
            "<script>",
            "SELECT c.*, cc.customer_name, nl.level_name, nt.nursing_name",
            "FROM customernurseitem c ",
            "LEFT JOIN customer cc ON c.customer_id = cc.customer_id ", 
            "LEFT JOIN nurselevel nl ON c.level_id = nl.id ",
            "LEFT JOIN nursecontent nt ON c.item_id = nt.id ",
            "<where>",
            "  c.is_deleted = 0", 
            "  <if test='ew != null and ew.sqlSegment != null and ew.sqlSegment.trim() != \"\"'>",
            "    AND ${ew.sqlSegment.replaceAll(\"customer_id\", \"c.customer_id\")}", // 替换动态条件中的 customer_id 为 c.customer_id
            "  </if>",
            "</where>",
            "</script>"
    })
    IPage<CustomerNurseItemDTO> pageDetails(@Param("page") Page<CustomerNurseItemDTO> page, @Param("ew") LambdaQueryWrapper<Customernurseitem> queryWrapper);

//    @Select("SELECT " +
//            "customer.customer_id, " +
//            "customer.customer_name, " +
//            "nursecontent.serial_number, " +
//            "nursecontent.nursing_name, " +
//            "nursecontent.service_price, " +
//            "customernurseitem.nurse_number, " +
//            "customernurseitem.maturity_time, " +
//            "nursecontent.STATUS " +
//            "FROM customer " +
//            "INNER JOIN customernurseitem ON customer.customer_id = customernurseitem.customer_id " +
//            "INNER JOIN nursecontent ON customernurseitem.item_id = nursecontent.id " +
//            "WHERE customer.customer_name LIKE CONCAT('%', #{customerName}, '%')")
    IPage<CustomerNurseItemDTO> selectCustomerNurseItemDetails(Page<CustomerNurseItemDTO> page, @Param("customerName") String customerName);
}